package com.tl.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tl.common.annotation.Log;
import com.tl.common.core.controller.BaseController;
import com.tl.common.core.domain.AjaxResult;
import com.tl.common.enums.BusinessType;
import com.tl.app.domain.AppCarousel;
import com.tl.app.service.IAppCarouselService;
import com.tl.common.utils.poi.ExcelUtil;
import com.tl.common.core.page.TableDataInfo;

/**
 * 轮播Controller
 * 
 * @author suhp
 * @date 2024-06-21
 */
@RestController
@RequestMapping("/app/carousel")
public class AppCarouselController extends BaseController
{
    @Autowired
    private IAppCarouselService appCarouselService;

    /**
     * 查询轮播列表
     */
    @PreAuthorize("@ss.hasPermi('app:carousel:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppCarousel appCarousel)
    {
        startPage();
        List<AppCarousel> list = appCarouselService.selectAppCarouselList(appCarousel);
        return getDataTable(list);
    }

    /**
     * 导出轮播列表
     */
    @PreAuthorize("@ss.hasPermi('app:carousel:export')")
    @Log(title = "轮播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppCarousel appCarousel)
    {
        List<AppCarousel> list = appCarouselService.selectAppCarouselList(appCarousel);
        ExcelUtil<AppCarousel> util = new ExcelUtil<AppCarousel>(AppCarousel.class);
        util.exportExcel(response, list, "轮播数据");
    }

    /**
     * 获取轮播详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:carousel:query')")
    @GetMapping(value = "/{carouselId}")
    public AjaxResult getInfo(@PathVariable("carouselId") Long carouselId)
    {
        return success(appCarouselService.selectAppCarouselByCarouselId(carouselId));
    }

    /**
     * 新增轮播
     */
    @PreAuthorize("@ss.hasPermi('app:carousel:add')")
    @Log(title = "轮播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppCarousel appCarousel)
    {
        return toAjax(appCarouselService.insertAppCarousel(appCarousel));
    }

    /**
     * 修改轮播
     */
    @PreAuthorize("@ss.hasPermi('app:carousel:edit')")
    @Log(title = "轮播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppCarousel appCarousel)
    {
        return toAjax(appCarouselService.updateAppCarousel(appCarousel));
    }

    /**
     * 删除轮播
     */
    @PreAuthorize("@ss.hasPermi('app:carousel:remove')")
    @Log(title = "轮播", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carouselIds}")
    public AjaxResult remove(@PathVariable Long[] carouselIds)
    {
        return toAjax(appCarouselService.deleteAppCarouselByCarouselIds(carouselIds));
    }
}
